<%@page import="com.ignou.mca.beans.UserVO"%>
<%@page import="com.ignou.mca.beans.ExamStatusBean"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="com.ignou.mca.beans.MailBean"%>
<%@page import="com.ignou.mca.utils.MailUtilities"%>
<%@page import="javax.mail.internet.AddressException"%>
<%@page import="javax.mail.MessagingException"%><html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="theme/style.css"
	media="screen" />
<title>OES - Exam Results</title>
</head>
<body onload="userfocus()">
	<div id="MainWrapper">
		<jsp:include page="header.jsp" /> 
		<jsp:include page="LeftContainer.jsp" />
		<div id="MainContent">
		<center><h2>Exam Results</h2></center>
		<%
			UserVO uvo = (UserVO) session.getAttribute("UserVO");
			if(uvo==null)
			{
				response.sendRedirect("./Login.jsp");
			}
			else
			{
				ExamStatusBean esb = (ExamStatusBean) session.getAttribute("ExamStatus");
				if(esb==null)
				{
					out.println("<center><font color='red'>Error while retriving exam result.</font></center>");
				}
				else
				{
					String greet = "";
					if(esb.getResult().equalsIgnoreCase("failed"))
					{
						greet = "<font color='red'>Better luck next time</font>";
					}else
					{
						greet = "<font color='green'>Congratulations!!!!</font>";
					}
					MailBean mb = new MailBean();
					mb.setUserName(uvo.getUserName());
					mb.setEmail(uvo.getEmail());
					mb.setScore(esb.getScore());
					mb.setFirstName(uvo.getFirstName());
					mb.setLastName(uvo.getLastName());
					mb.setExamDate(esb.getCompletionDate());
					mb.setExamResult(esb.getResult());
					try 
					{
						MailUtilities.sendMail("examresult",mb);
					} catch (AddressException e) 
					{
						// TODO Auto-generated catch block
						e.printStackTrace();
					} 
					catch (MessagingException e) 
					{
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					%>
					<center>
						<h2>Exam Results</h2>
						<table>
							<tr><td>Exam Id</td> <td><%=esb.getExamId() %></td></tr>
							<tr><td>Exam Score</td> <td><%=esb.getScore() %></td></tr>
							<tr><td>Exam Result</td> <td><%=esb.getResult() %></td></tr>
							<tr><td></td> <td><%=greet %></td></tr>

						</table>
					</center>
					<%
				}
			}
		%>
			
		</div>
		<jsp:include page="footer.jsp" />
	</div>
</body>
</html>